

import static org.junit.Assert.*;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;

import org.junit.Before;
import org.junit.Test;

public class WhenATicketTimeCallsGetTimeLeft {
	
	private Calendar now;
	private TicketTime t;
	private Calendar ticketComes;

	@Before 
	public void setup() {
		now = Calendar.getInstance();
		now.set(2012,0,10,15,0, 0);
		ticketComes = new GregorianCalendar();
	}
	
	@Test
	public void andTicketComesAt2012_0_10_12_00AndIsPrioWhiteWeShouldGet15h() {
		ticketComes.set(2012, 0, 10, 12, 0,0);
		t = new TicketTime(ticketComes.getTime(), now.getTime(), 18);
		assertEquals("1T 06:00:00",t.getCurrentTimeLeft());
		
	}
	
	@Test
	public void andTicketComesAt2012_0_10_14_00AndIsPrioWhiteWeShouldGet17h() {
		ticketComes.set(2012, 0, 10, 14, 0,0);
		t = new TicketTime(ticketComes.getTime(), now.getTime(), 18);
		assertEquals("1T 08:00:00",t.getCurrentTimeLeft());
		
	}
	
	@Test
	public void andTicketComesAt2012_0_09_12_00AndIsPrioWhiteWeShouldGet6h() {
		ticketComes.set(2012, 0, 9, 12, 0,0);
		t = new TicketTime(ticketComes.getTime(), now.getTime(), 18);
		assertEquals("0T 06:00:00",t.getCurrentTimeLeft());
		
	}
	
	
	@Test
	public void andTicketComesAt2012_0_09_18_00AndIsPrioWhiteWeShouldGet11h() {
		ticketComes.set(2012, 0, 9, 18, 0,0);
		t = new TicketTime(ticketComes.getTime(), now.getTime(), 18);
		assertEquals("1T 02:00:00",t.getCurrentTimeLeft());
		
	}
	
	@Test
	public void andTicketComesAt2012_0_05_12_00AndIsPrioWhiteWeShouldGetMinus12h() {
		ticketComes.set(2012, 0, 5, 12, 0,0);
		t = new TicketTime(ticketComes.getTime(), now.getTime(), 18);
		assertEquals("-0T 03:00:00",t.getCurrentTimeLeft());
		
	}
	
	@Test
	public void andTicketComesAt2012_0_09_18_10AndIsPrioWhiteWeShouldGet11h00m() {
		ticketComes.set(2012, 0, 9, 18, 10,0);
		t = new TicketTime(ticketComes.getTime(), now.getTime(), 18);
		assertEquals("1T 02:00:00",t.getCurrentTimeLeft());
		
	}
	
	@Test
	public void andTicketComesAt2012_0_09_16_10AndIsPrioWhiteWeShouldGet10h10m() {
		ticketComes.set(2012, 0, 9, 16, 10,0);
		t = new TicketTime(ticketComes.getTime(), now.getTime(), 18);
		assertEquals("1T 01:10:00",t.getCurrentTimeLeft());
		
	}
	
	@Test
	public void andTicketComesAt2012_0_05_12_10AndIsPrioWhiteWeShouldGetMinus11h50m() {
		ticketComes.set(2012, 0, 5, 12, 10,0);
		t = new TicketTime(ticketComes.getTime(), now.getTime(), 27);
		assertEquals("0T 06:10:00",t.getCurrentTimeLeft());
		
	}
	
	
	@Test
	public void andTicketComesAt2012_0_09_07_54AndIsPrioWhiteWeShouldGet2h() {
		ticketComes.set(2012, 0, 9, 7, 54,0);
		t = new TicketTime(ticketComes.getTime(), now.getTime(), 18);
		assertEquals("0T 02:00:00",t.getCurrentTimeLeft());
		
	}
	
	@Test
	public void andTicketComesAt2012_0_09_7_54AndNowIs2012_0_10_07_30ThenWeShouldGet9h() {
		ticketComes.set(2012, 0, 9, 7, 54,0);
		now.set(2012, 0, 10, 7, 30,0);
		t = new TicketTime(ticketComes.getTime(), now.getTime(), 18);
		assertEquals("1T 00:00:00",t.getCurrentTimeLeft());
	}
	
	@Test
	public void andTicketComesAt2012_0_05_15_10AndIsPrioWhiteWeShouldGetMinus11h50m() {
		ticketComes.set(2012, 0, 5, 15, 10,0);
		t = new TicketTime(ticketComes.getTime(), now.getTime(), 18);
		assertEquals("0T 00:10:00",t.getCurrentTimeLeft());
		
	}

	@Test
	public void andTicketComesAt2012_0_09_7_54AndNowIs2012_0_09_07_30ThenWeShouldGet18h() {
		ticketComes.set(2012, 0, 9, 7, 54,0);
		now.set(2012, 0, 9, 7, 30,0);
		t = new TicketTime(ticketComes.getTime(), now.getTime(), 18);
		assertEquals("2T 00:00:00",t.getCurrentTimeLeft());
	}
	
	@Test
	public void andTicketComesAt2012_0_9_10_00AndNowIs2012_0_09_10_00ThenWeShouldGet27h() {
		ticketComes.set(2012, 0, 9, 10, 0,0);
		now.set(2012, 0, 9, 10, 0,0);
		t = new TicketTime(ticketComes.getTime(), now.getTime(), 27);
		assertEquals("3T 00:00:00",t.getCurrentTimeLeft());
	}
	
	@Test
	public void andTicketComesAt2012_0_9_10_00AndNowIs2012_0_09_09_50ThenWeShouldGet27hAnd10Minutes() {
		ticketComes.set(2012, 0, 9, 10, 0,0);
		now.set(2012, 0, 9, 9, 50,0);
		t = new TicketTime(ticketComes.getTime(), now.getTime(), 27);
		assertEquals("3T 00:10:00",t.getCurrentTimeLeft());
	}
	
	@Test
	public void andTicketComesAt2012_0_09_8_54AndNowIs2012_0_09_06_40ThenWeShouldGet18h54Minutes() {
		ticketComes.set(2012, 0, 5, 8, 54,0);
		now.set(2012, 0, 9, 6, 40,0);
		t = new TicketTime(ticketComes.getTime(), now.getTime(), 27);
		assertEquals("2T 00:54:00",t.getCurrentTimeLeft());
	}
	
	
	@Test
	public void andTicketComesAt2012_0_10_08_10AndIsPrioWhiteWeShouldGet12_01_2012_08_10_00() {
		SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
		ticketComes.set(2012, 0, 10, 8, 10,0);
		t = new TicketTime(ticketComes.getTime(), now.getTime(), 18);
		assertEquals("12.01.2012 08:10:00",sdf.format(t.getEndZeit()));
		
	}
	
	@Test
	public void andTicketComesAt2012_0_09_17_10WeShouldGet11h00m() {
		ticketComes.set(2012, 0, 9, 17, 10,0);
		t = new TicketTime(ticketComes.getTime(), now.getTime(), 18);
		assertEquals("1T 02:00:00",t.getCurrentTimeLeft());
		
	}
	
	@Test
	public void andTicketComesAt2012_0_09_17_10AndIsPrioWhiteWeShouldGet12_01_2012_08_10_00() {
		SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
		ticketComes.set(2012, 0, 9, 17, 10,0);
		t = new TicketTime(ticketComes.getTime(), now.getTime(), 18);
		assertEquals("12.01.2012 08:00:00",sdf.format(t.getEndZeit()));
		
	}

}
